function mofo() 
	RunMacroText("/dance")
end
ccR = {
	Key = {	
		One =
		function() 
			if ccR.Var("Key1") ~= nil then _G[ccR.Var("Key1")]() end
		end, 
		Two =
		function() 
			if ccR.Var("Key2") ~= nil then _G[ccR.Var("Key2")]() end
		end, 
		Three =
		function() 
			if ccR.Var("Key3") ~= nil then _G[ccR.Var("Key3")]() end
		end, 
		Four =
		function() 
			if ccR.Var("Key4") ~= nil then _G[ccR.Var("Key4")]() end
		end, 
		Five =
		function() 
			if ccR.Var("Key5") ~= nil then _G[ccR.Var("Key5")]() end
		end, 
		Six =
		function() 
			if ccR.Var("Key6") ~= nil then _G[ccR.Var("Key6")]() end
		end, 
		Seven =
		function() 
			if ccR.Var("Key7") ~= nil then _G[ccR.Var("Key7")]() end
		end, 
		Eight =
		function() 
			if ccR.Var("Key8") ~= nil then _G[ccR.Var("Key8")]() end
		end, 
		Nine =
		function() 
			if ccR.Var("Key9") ~= nil then _G[ccR.Var("Key9")]() end
		end, 
	},
	Save = function()
		ccR_Save = {}
		for Index = 1, ObjectCount() do
			local Object = ObjectWithIndex(Index);
			if Object ~= nil then
				if ObjectIsType(Object, ObjectTypes.Unit) then
					local Name = ccR.Unit.Name(Object)
					local GUID = ccR.Unit.GUID(Object)
					local NPCID = ccR.Unit.NPCID(Object)
					ccR_Save[#ccR_Save+1] = NPCID .. " - " .. Name .. " - " .. GUID
				end
			end
		end
		ccR.PrintToChat("Saved complete.")
	end,

	Add_Rotation =
	function(spec, name, description, talents, abilities, features, setup)
		ccR.Rotations[#ccR.Rotations+1] = { spec, name, description, talents, abilities, features, setup}
	end,

	Start_Attack = 
	function() 
		if ccR.Target.Is.Attackable() then
			if ccR.Player.Is.Melee() and ccR.Unit.Is.WithinMelee("target", "player") then StartAttack() end
			if ccR.Player.Is.Ranged() and ccR.Unit.Distance("target", "player") <= 40 then StartAttack() end
		end 
	end,

	CastAttack = function(spell, unit, delay) ccR.Cast.Attack(spell, unit, delay) end,
	CastAoE = function(spell, unit, maxRange, yards) ccR.Cast.AoE(spell, unit, maxRange, yards) end,
	CastDebuff = function(spell, unit) unit = unit or "target" ccR.Cast.Attack(spell, unit, true) end,
	Execute = function(spell, unit) end,
	MassDebuff = function(spell, limit, range, requiresFacing, debuffRemaining) ccR.Cast.Mass.Debuff(spell, limit, range, requiresFacing, debuffRemaining) end,
	MassExecute = function(spell, limit, range, requiresFacing) ccR.Cast.Mass.Execute(spell, limit, range, requiresFacing) end,

	DebuffCount =
	function(spell)
		local vHasDebuff = 0
		for x = 1, # ccR_Enemies_In_Combat do
			local vUnit = ccR_Enemies_In_Combat[x]
			if ccR.Unit.Has.MyDebuff(vUnit, spell) 
			then
				vHasDebuff = vHasDebuff + 1 
			end
		end
		return vHasDebuff
	end,
	RemoveBuff = function(buff) for x = 0, 40 do local vBuff = UnitBuff("player", x) if vBuff ~= nil and vBuff == GetSpellInfo(buff) then CancelUnitBuff("player", x) return end end end,

	table_empty = function(tbl) for i = 0, #tbl do tbl[i] = nil end end,
	ConvertToName = function(spell) if tonumber(spell) ~= nil then spell = GetSpellInfo(spell) end return spell end,

	Error = function(msg) ccR.Sys.Error(msg) end,
	PrintToChat = function(msg) ccR.Sys.PrintToChat(msg) end,
	Default = 
	function(var, save) 
		if ccR.Var(var) == nil then ccR.Var(var, save) end 
	end,
	Settings = function(var, save) ccR.Var(var, save) end,
	Var = function(var, save)
		local class = select(2, UnitClass("player"))
		local spec = GetSpecialization()
		if spec == nil then spec = "LowLevel" end
		if class ~= nil
		and spec ~= nil
		then
			var = class .. "_" .. spec .. "_" .. var
			if save == nil then 
				return ccR_Settings[var] 
			else
				if tonumber(save) ~= nil then
					ccR_Settings[var] = tonumber(save)
				else
					ccR_Settings[var] = save 
				end
			end
		end
	end,

	Tooltip = 
	function(input, obj, string)
		if not ccRTT then
			CreateFrame("GameTooltip","ccRTT",UIParent,"GameTooltipTemplate")
			ccRTT:SetOwner(UIParent,"ANCHOR_NONE")
		else
			if input == "spell" then
				ccRTT:ClearLines()
				ccRTT:SetSpellByID(obj)
				for x = 1, ccRTT:NumLines() do
					local vLine = _G["ccRTTTextLeft" .. tostring(x)]:GetText()
					if vLine ~= nil then
						local vSearch = string.match(vLine, string .. " (%d+%p%d+)")
						if vSearch == nil then vSearch = string.match(vLine, string .. " (%d+)") end
						if vSearch ~= nil then 
							if string.find(vSearch, ",") ~= nil then
								vSearch = gsub(vSearch, ",", "")
								return tonumber(vSearch)
							else
								return tonumber(vSearch)
							end
						end
					end
				end	
				return
			end
			if input == "debuff" then
				-- Rend
				-- ccR.Tooltip("debuff", "target", "Bleeding for")
				for i = 1, 40 do
					ccRTT:ClearLines()
					ccRTT:SetUnitAura(obj, i, "PLAYER|HARMFUL")
					for x = 1, ccRTT:NumLines() do
						local vLine = _G["ccRTTTextLeft" .. tostring(x)]:GetText()
						if vLine ~= nil then
							local vSearch = string.match(vLine, string .. " (%d+)")
							if vSearch ~= nil then 
								return tonumber(vSearch)
							end
						end
					end				
				end
				return
			end
			if input == "word" then
				if obj == nil and ccR.Target.Exists() then obj = "target" end
				ccRTT:SetUnit(obj)
				for x = 1, ccRTT:NumLines() do
					local vLine = _G["ccRTTTextLeft" .. tostring(x)]:GetText()
					if vLine ~= nil then
						local vSearch = string.match(vLine, string) 
						if vSearch ~= nil then 
							return true
						end
					end
				end
				return false
			end
		end
	end,

	StopCasting =
	function(spell, time)
		if time == nil then time = 0.5 end
		if spell ~= nil then
			if tonumber(spell) then
				if 	(ccR.Player.Is.Casting() and not ccR.Player.Has.LeftOnCast(spell))
					or
					(ccR.Player.Is.Channeling() and not ccR.Player.Has.LeftOnChannel(spell))
				then
					SpellStopCasting()
				end
			else
				if type(spell) == "table" then
					for x = 1, # spell do 
						if (
								(ccR.Player.Is.CastingSpell(spell[x]) and not ccR.Player.Has.LeftOnCast(time))
								or
								(ccR.Player.Is.ChannelingSpell(spell[x]) and not ccR.Player.Has.LeftOnChannel(time))
							)
						then
							SpellStopCasting() 
						end
					end
				end
				if type(spell) == "string" then
					if 	(ccR.Player.Is.CastingSpell(spell) and not ccR.Player.Has.LeftOnCast(time))
						or
						(ccR.Player.Is.ChannelingSpell(spell) and not ccR.Player.Has.LeftOnChannel(time))
					then
						SpellStopCasting()
					end
				end
			end
		else
			SpellStopCasting()
		end
	end,

}

ccR.Rotations = {}
setmetatable(ccR.Rotations, ccR)
